package com.pajk.user.api.http;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.pajk.test.api.BaseTest;
import com.pajk.test.client.ContextHelper;
import com.pajk.user.dal.index.Index;
import com.pajk.user.dal.index.TairIndex;
import com.pajk.user.service.login.sms.SmsPasswordManager;
import com.pajk.user.service.login.sms.SmsPasswordManager.SmsInfo;
import com.pingan.jk.api.request.ApiCode;
import com.pingan.jk.api.request.User_SmsPasswordLogin;
import com.pingan.jk.api.resp.Api_USER_LoginResp;
import com.pingan.jk.client.ApiContext;
import com.pingan.jk.client.BaseRequest;

public class User_SmsPasswordLoginIT extends BaseTest{
	private ClassPathXmlApplicationContext appContext = null;
    private Index<String,SmsPasswordManager.SmsInfo> smsInfoIndex = null;
    private TairIndex<Long, Long> mobileToUserIdIndex = null;
    
    @BeforeClass
	public void setup() {
//		this.appContext = new ClassPathXmlApplicationContext(
//				"classpath:META-INF/spring/user-service-consumer.xml");
//		this.appContext.start();
//		this.smsInfoIndex = (Index<String, SmsInfo>) this.appContext.getBean("smsInfoIndex");
//		this.mobileToUserIdIndex = (TairIndex<Long, Long>) this.appContext.getBean("mobileToUserIdIndex");
	}

	@AfterClass
	public void teardown() {
//		this.appContext.close();
	}
	
	//有问题，不通！--如何获取sms，进行登录验证，怎样构造数据?
	@Test(description="user.smsPasswordLogin 短信动态密码登录  SecurityType.MobileOwnerTrustedDevice")
	public void smsPasswordLoginTest(){
//		ApiContext context = super.mobileOwnerTrustedDevice();
//		
//		String mobile = "13819453412";
////        User_RequestSmsPassoword req = new User_RequestSmsPassoword(mobile,"REGISTER");
////        ContextHelper.sendRequest(context, new BaseRequest[] { req });
////        Assert.assertEquals(ApiCode.SUCCESS, req.getReturnCode());
////        Api_USER_UpstreamSmsInfo res = req.getResponse();
////		Assert.assertNotNull(res);
////		System.out.println(res.upstreamSmsPhoneNumber);//13819453412
////		Assert.assertEquals(res.upstreamSmsPhoneNumber, mobile);
////		System.out.println(res.smsContent);//U154482
//		
////		mobileToUserIdIndex.put(13819453412L, 1234567890909L);
////		
////		String dynamic = "123456";
////    	SmsPasswordManager smsPasswordManager = new SmsPasswordManager();
////    	SmsPasswordManager.SmsInfo smsInfo = smsPasswordManager.new SmsInfo();
////    	smsInfo.correctHits=0;
////    	smsInfo.upstreamPassword = "U"+dynamic;
////    	smsInfo.downstreamPassword = dynamic;
////    	smsInfo.timeStamp = new Date();
////    	smsInfoIndex.put(mobile, smsInfo);
//    	
//		//这里只能走真实的？
//		String dynamic = "";
//		SmsPasswordManager.SmsInfo smsInfo = smsInfoIndex.get(mobile);
//    	if(smsInfo != null) {
//    		dynamic = smsInfo.downstreamPassword;
//    	}
//		context.setPhoneNumberAndDynamic(mobile, dynamic);
//		
//		
//		User_SmsPasswordLogin req2 = new User_SmsPasswordLogin();
//        ContextHelper.sendRequest(context, new BaseRequest[] { req2 });
//        Assert.assertEquals(req2.getReturnCode() ,ApiCode.SUCCESS);
//        Api_USER_LoginResp res2 = req2.getResponse();
//		Assert.assertNotNull(res2);
//		System.out.println(res2.expire);
//		System.out.println(res2.token);
//		System.out.println(res2.uid);
		
	}
}
